import * as TYPE from './type';
import {toGet, toPost, toDel, toPut} from '../../utils/MyAxios';
import {Notice} from 'iview';

/*获取用户列表*/
export const getAcUser = ({commit}, params) => {
  toGet('/authentication/user/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.ACUSER, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取用户列表失败',
          desc: response.resultMsg
        });
      }
    });
};
/*获取角色列表*/
export const getAcRole = ({commit}, params) => {
  toGet('/authentication/role/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.ACROLE, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取角色列表失败',
          desc: response.resultMsg
        });
      }
    });
};
/*获取权限菜单列表*/
export const getAcMenu = ({commit}, params) => {
  toGet('/authentication/menu/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.ACMENUS, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取权限菜单列表失败',
          desc: response.resultMsg
        });
      }
    });
};
/*获取简略用户信息列表*/
export const getSimpleUser = ({commit}, params) => {
  toGet('/authentication/user/queryS/'+localStorage.getItem("userId"))
    .then((response) => {
      if (response.resultCode === 0) {
        commit(TYPE.SIMPLEUSER, {
          simpleUser:response.data
        });
      }
      else {
        Notice.error({
          title: '获取简略用户信息列表',
          desc: response.resultMsg
        });
      }
    });
};
